package com.myGis.entities;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.GeometryCollection;

@Entity
@Table(name = "MYGIS_SPATIAL_OBJECT", catalog = "public")
public class SpatialObject {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "SPATIAL_OBJECT_ID", unique = true, nullable = false)
	private Long spatialObjectId;

	@Column(name = "GEOMETRY", nullable = false)
	@Type(type = "org.hibernate.spatial.GeometryType")
	private GeometryCollection geometry;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "LAYER_ID", nullable = false)
	private Layer layer;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "spatialObject", cascade = CascadeType.ALL)
	private List<ValueField> valueFields;

	public SpatialObject() {
		valueFields = new ArrayList<ValueField>();
	}

	/**
	 * @return the layer
	 */
	public Layer getLayer() {
		return layer;
	}

	/**
	 * @param layer
	 *            the layer to set
	 */
	public void setLayer(Layer layer) {
		this.layer = layer;
	}

	/**
	 * @return the spatialObjectId
	 */
	public Long getSpatialObjectId() {
		return spatialObjectId;
	}

	/**
	 * @param spatialObjectId
	 *            the spatialObjectId to set
	 */
	public void setSpatialObjectId(Long spatialObjectId) {
		this.spatialObjectId = spatialObjectId;
	}

	/**
	 * @return the valueFields
	 */
	public List<ValueField> getValueFields() {
		return valueFields;
	}

	/**
	 * @param valueFields
	 *            the valueFields to set
	 */
	public void setValueFields(List<ValueField> valueFields) {
		this.valueFields = valueFields;
	}

	/**
	 * @return the geometry
	 */
	public GeometryCollection getGeometry() {
		return geometry;
	}

	/**
	 * @param geometry the geometry to set
	 */
	public void setGeometry(GeometryCollection geometry) {
		this.geometry = geometry;
	}
}
